﻿<!doctype html>
<html>
    <head>
        <script language="Javascript">
            function selectByValue(form, str){
                for (i=0; i<form.childElementCount; i++){
                    if (form[i].value == str){
                        form[i].selected = "i";
                    }
                }
            }
			
			fonction(objet) {
				alert(objet.value);
				if (objet.value=="new")
				{
					 document.getElementById("pourquoi1").style.display="";
					 document.getElementById("pourquoi2").style.display="";
				}
			}
        </script>
        <?php
            function input($type){
                require('php/connexionBaseDeDonnees.php');
                switch ($type){
					case 'id':
						echo '<i>0</i>';
					break;
                    case 'idDisque':
						$temp = $bd->query('Select titre from '.$_GET['mode']);
						$temp = $temp->fetchAll();
						echo "<select>\n";
						foreach ($temp as $titre){
							echo "<option name='".$titre[0]."' value='".$titre[0]."'>".$titre[0]."</option>\n";
						}
						echo "</select>\n";
					break;
						
                    case 'idOriginal':
						$temp = $bd->query('Select titre from disque');
						$temp = $temp->fetchAll();
						echo "<select>\n";
						foreach ($temp as $titre){
							echo "<option name='".$titre[0]."' value='".$titre[0]."'>".$titre[0]."</option>\n";
						}
						echo "</select>\n";
                    break;
					
                    case 'support':
						echo "<select><option>CD</option><option>Disquette 5 1/2</option><option>DVD</option><option>LD</option><option>vynile</option></select>";
					break;
					
                    /*case 'idColl':
						echo '<input type="text" name="idColl" value="" size="10" /><br />';
						echo '<select  name="nom_select" onchange="document.ex.idColl.value = document.ex.s.options[document.ex.s.selectedIndex].value;document.ex.s.value=\'\'">
						<option value="Loads of Paperz">Loads of Paperz</option>
						<option value="Loads of Paperz">Discographie de Bach</option>
						<option value="Loads of Paperz">Compositions RAPides</option>
						</select>';
						
					break;*/
					
					default:
						echo "<input name='$type' />";
					break;
				}
			}
        ?>
        <meta charset="utf-8">
        <title>Médiathéque - Administration</title>
        <?php include('communs/lienCssAdmin.php'); ?>
        <script type="text/javascript" src="js/dropdown/jquery.js"></script>
    </head>
    <body>
        <div id="conteneurTete">
            <?php include('communs/enTete.php'); ?>
        </div> 
        <?php include('communs/menuAdmin.php'); ?>   
        <div id="conteneurCorps">
			<h2> Ajouter un média </h2>
			Type:
            <select id='mode' name='mode' onchange="window.location='AdminMedias.php?mode=' + this.value">
                <option disabled="disabled" selected="selected">Sélectionner un support</option>
                <option value='disque'>Disque</option>
                <option value='film'>Film</option>
                <option value='piste'>Piste</option>
                <option value='episode'>Épisode</option>
                <option value='document'>Document</option>
            </select>
            <script language="Javascript">
                var mod = "<?php if (isset($_GET['mode'])){echo $_GET['mode']; };?>";
                selectByValue(document.myform.mode, mod);                    
            </script>
            <br /><br />
			<form name='ex' id='ex'>
            <table>
            <?php
                require('php/connexionBaseDeDonnees.php');
                if (isset($_GET['mode'])){
                    $mod = $_GET['mode'];
                    $temp = $bd->query("describe $mod");
                    while ($field = $temp->fetch()){
                        echo "<tr>\n<td>\n".$field[0]." :\n</td>\n<td>\n";
						echo input($field[0]);
						echo "</td>\n</tr>\n";
                    }
					echo "</table>";
					echo "<br /><br />";
					if ($mod == 'piste'){
						echo "<table>
							<caption>Interprètes</caption>
							<tr>
								<th>Nom</th>
							</tr>
							<tr>
								<td><input /></td>
							</tr>
							<tr>
								<td><input /></td>
							</tr>
							<tr>
								<td><input /></td>
							</tr>
							<tr>
								<td><input /></td>
							</tr>
							<tr>
								<td><input /></td>
							</tr>
						</table>\n";
					}elseif ($mod == 'film'){
						echo "<table>
							<caption>Acteurs</caption>
							<tr>
								<th>Nom</th>
							</tr>
							<tr>
								<td><input /></td>
							</tr>
							<tr>
								<td><input /></td>
							</tr>
							<tr>
								<td><input /></td>
							</tr>
							<tr>
								<td><input /></td>
							</tr>
							<tr>
								<td><input /></td>
							</tr>
						</table>\n";
					}elseif ($mod == 'disque'){
						echo "<table>
							<caption>Artistes</caption>
							<tr>
								<th>Nom</th>
							</tr>
							<tr>
								<td><input /></td>
							</tr>
							<tr>
								<td><input /></td>
							</tr>
							<tr>
								<td><input /></td>
							</tr>
							<tr>
								<td><input /></td>
							</tr>
							<tr>
								<td><input /></td>
							</tr>
						</table>\n";
					}
				
                }
            ?>
            <tr><td><input type='button' value='Enregistrer'/></td></tr>
            </table>
        <br /><br />
        <a href="indexAdmin.php">Retour</a>
        </div>
        <div id="conteneurPied">
            <?php include('communs/piedDePage.php'); ?>   
        </div>
    </body>
</html>